package com.jtjrenren.android.taxi.passenger.core.wallect.main;

import android.content.Intent;
import android.widget.TextView;

import com.jtjrenren.android.taxi.passenger.core.wallect.balance.BalaceActivity;
import com.jtjrenren.android.taxi.passenger.core.wallect.coupons.CouponsActivity;
import com.jtjrenren.android.taxi.passenger.Constants;
import com.jtjrenren.android.taxi.passenger.core.wallect.jindou.JinDouActivity;
import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.base.BaseActivity;
import com.jtjrenren.android.taxi.passenger.bean.User;
import com.jtjrenren.android.taxi.passenger.bean.api.ApiAmount;
import com.jtjrenren.android.taxi.passenger.manger.AppManger;
import com.jtjrenren.android.taxi.passenger.manger.api.ApiWorks;
import com.library.utils.LogUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by wdl on 2016/1/27.
 */
public class WallectActivity extends BaseActivity {
    @BindView(R.id.wallect_balance_desc)
    TextView tv_balance;
    @BindView(R.id.wallect_cardnum_desc)
    TextView tv_cardnum;
    @BindView(R.id.wallect_coupons_desc)
    TextView tv_coupons;
    @BindView(R.id.wallect_jindou_desc)
    TextView tv_jindou;
    @BindView(R.id.title)
    TextView tv_title;

    private User currentUser;

    @Override
    public int getLayoutId() {
        return R.layout.aty_wallect_main;
    }

    @Override
    public void init() {
        tv_title.setText("钱包");
        currentUser = AppManger.getInstance().user;


    }

    @Override
    protected void onResume() {
        super.onResume();

        getWallectDetails();
    }

    @OnClick(R.id.title_left)
    public void clickBack() {
        finish();
    }

    @OnClick(R.id.wallect_balance)
    public void clickBalance() {
        startActivity(new Intent(this, BalaceActivity.class));
    }


    @OnClick(R.id.wallect_myjindou)
    public void clickJd() {
        startActivity(new Intent(this, JinDouActivity.class));
    }


    @OnClick(R.id.wallect_coupons)
    public void clickCpupons() {
        startActivity(CouponsActivity.getDiyIntent(this, Constants.DEFAULT_COUPONS_LIST_ALL, false, null));
    }


    public void refreshView(ApiAmount.DataListEntity amount) {
        LogUtil.log("wallect", "账号信息：返回结果--刷新");
        AppManger.getInstance().user.setRMBMoney(amount.getMoney() + "");
        AppManger.getInstance().user.setCredits(amount.getKingtou() + "");
        tv_balance.setText(amount.getMoney() + "");
        tv_cardnum.setText(amount.getCardCounts() + "");
        tv_jindou.setText(amount.getKingtou() + "");
        tv_coupons.setText(amount.getCoupoCounts() + "");
    }

    /**
     * 获取用户资金账户详情
     */
    private void getWallectDetails() {
        ApiWorks.getUserAmountDetails(currentUser.getWorkNo(), new ApiWorks.ResponseListener<ApiAmount>() {
            @Override
            public void onResponse(ApiAmount apiAmount) {
                if (apiAmount != null && apiAmount.getDataList() != null && apiAmount.getDataList().size() > 0) {
                    ApiAmount.DataListEntity amount = apiAmount.getDataList().get(0);
                    refreshView(amount);
                    AppManger.getInstance().refreshQBYE(amount.getMoney());
                } else {

                }
            }
        });
    }
}
